<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.util.*"%>    
<%@ page import="java.sql.*,java.util.*,model.User,service.UserService"%> 
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户信息列表</title>
</head>
<%
UserService service; 
List<User> list = null;
User user=(User)session.getAttribute("user"); 
if (user==null){
   out.println("未登陆，2秒后跳转至login.jsp");
   response.setHeader("refresh", "2;URL=login.jsp");
}
%>
<body>
<% if (user!=null) {%>
  <div align="right"><u><a href="login.jsp">退出登录</a></u></div><!-- 跳转登录页面 -->
 <h3><span style="font-weight:bold;font-family:'楷体'"> 欢迎您，<%=user.getUsername()%></span></h3> 
 <h4><span style="font-weight:bold;font-family:'楷体'">个人信息：</span></h4>
<form action="EditMessageServlet" method="get"> 
<p>用户名：<%=user.getUsername()%>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;性别：<%=user.getGender()%></p>
<p>&nbsp;密码&nbsp;&nbsp;&nbsp;：<input type="text" name="password" value="<%=user.getPassword() %>"/>&nbsp;&nbsp;&nbsp;&nbsp;年龄：<input type="text" name="age" value="<%=user.getAge() %>"  /></p>
<p>电子邮箱：<input type="text" name="email" value="<%=user.getEmail()%>"  /></p>
 注册时间：<%=user.getRegdatetime()%><br>
  <div align="center"><input type="submit" value="修改"/></div> 
   </form>
 <span style="font-weight:bold;font-family:'楷体'">所有用户列表：</span>
    <center><table bgcolor="#9999dd" border="1" width="700">
    <tr>
    <td>用户号</td>
    <td>用户名</td>
    <td>性别</td>
    <td>年龄</td>
    <td>电子邮箱</td>
    <td>注册时间</td>    
    </tr>
    <% 
       service = new UserService();
       try{
    	   list = service.findAll();
       }catch(Exception e){
    	   e.printStackTrace();
       }
       for(int i = 0;i<list.size();i++){
    	   User u = list.get(i);
       %>
       <tr>
       <td><%=u.getUserid() %></td>
       <td><%=u.getUsername() %></td>
       <td><%=u.getGender() %></td>
       <td><%=u.getAge() %></td>
       <td><%=u.getEmail() %></td>
       <td><%=u.getRegdatetime() %></td>
       </tr>
    <%	   
       }
    %>
    </table>
    </center> 
  <% 
  }%>
</body>
</html>